﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;
using System.IO;
using System.Data;
using DTN.Core;
using Hanel.DTN.News;

public partial class _Default : System.Web.UI.Page
{
    ItblContentManager obj = tblContentManager.CreateInstance();
    ItblCommentManager objCom = tblCommentManager.CreateInstance();
    ItblEventManager objEvent = tblEventManager.CreateInstance();
    ItblVoteCriteriaManager objVoteCri = tblVoteCriteriaManager.CreateInstance();
    ItblVotesManager objvotes = tblVotesManager.CreateInstance();
    protected void Page_Load(object sender, EventArgs e)
    {
        DisplayDienAnh();
        DisplayLamDep();
        DisplaySucKhoe();
        DisplayAmThuc();
       
    }
    protected override void Render(HtmlTextWriter writer)
    {
        StringBuilder sb = new StringBuilder();
        StringWriter sw = new StringWriter(sb);
        HtmlTextWriter hWriter = new HtmlTextWriter(sw);
        base.Render(hWriter);
        string PageResult = sb.ToString();
        using (StreamWriter outfile =
        new StreamWriter(Server.MapPath("Home.html")))
        {
            outfile.Write(PageResult);
        }
        writer.Write(PageResult);
    }
    protected void DisplayDienAnh()
    {
        
        DataTable dt = obj.SelecttblContentDynamic_top("Top 2", "Status=1 and ChannelID=49", "DatePage desc");

        DataList1.DataSource = dt;
        DataList1.DataBind();
    }
    protected void DisplayLamDep()
    {
       
        DataTable dt = obj.SelecttblContentDynamic_top("Top 2", "Status=1 and ChannelID=107", "DatePage desc");

        DataList2.DataSource = dt;
        DataList2.DataBind();
    }

    protected void DisplaySucKhoe()
    {
        
        DataTable dt = obj.SelecttblContentDynamic_top("Top 2", "Status=1 and ChannelID=106", "DatePage desc");

        DataList3.DataSource = dt;
        DataList3.DataBind();
    }

    protected void DisplayAmThuc()
    {
        
        DataTable dt = obj.SelecttblContentDynamic_top("Top 2", "Status=1 and ChannelID=82", "DatePage desc");

        DataList4.DataSource = dt;
        DataList4.DataBind();
    }

    public string bindPhanHoi()
    {
        string data = string.Empty;
        try
        {           
            DataTable dt = objCom.SelecttblCommentDynamic_top("Top 10","active=1 ", "com_create desc");

            data += "<div class=\"number-tv-trade\">";
            data += "   <div class=\"pnlTopComment\">";
            data += "       <div class=\"pnl-title\"><a class=\"tab-item-title selected\">PHẢN HỒI MỚI NHẤT</a></div>";
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                DataRow dr = dt.Rows[i];

                data += "       <div class=\"pnl-content\">";
                data += "           <div class=\"newsCnt\" showlead=\"true\">";
                data += "               <a href=\"News.aspx?id="+dr["Content_ID"].ToString() +"\" lead=\"true\">"+ToolCatChuoi.GetShortReview(dr["TieuDe"].ToString(),20)+ "</a>";
                data += "               <div class=\"leadContent none\">" + ToolCatChuoi.GetShortReview(dr["NoiDung"].ToString(), 20) + "</div>";
                data += "           </div>";
                data += "       </div>";           
            }
            data += "   </div><br class=\"clear\">";
            data += "</div>";
        }
        catch
        {
            return data;
        }
        return data;
    }

    public string BindEvent() //Muc cac su kien
    {
        string data = string.Empty;
        try
        {

            DataTable dt = objEvent.SelecttblEventDynamic_top("Top 4", "active=1", "[Order] desc");
            data += "<div id=\"eventSlide\" class=\"panel1 event w190px\">";
            data += "<div class=\"pnl-top top\">";
            data += "<ul class=\"mainNav\">";
            data += "<li class=\"prev\"><a href=\"javascript:void(0)\">«</a></li>";
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                DataRow dr = dt.Rows[i];
                data += "<li class=\"itm\"><a class=\"selected\" href=\"javascript:void(0)\">" + (i + 1) + "</a>";
                data += "<div class=\"slideContent none\">";
                data += "<a href=\"News.aspx?event=" + dr["id"] + "\" class=\"mainArtLink\"><img src=\"" + dr["LinkImage"] + "\"></a>";
                data += "<p class=\"title\">" + dr["Name"] + "</p>";
                data += "</div>";
                data += "</li>";

            }
            data += "<li class=\"next\"><a href=\"javascript:void(0)\">»</a></li>";
            data += "</ul>";
            data += "<a href=\"\" class=\"pnl-title\">SỰ KIỆN</a>";
            data += "</div>";
            data += "<div style=\"display: block;\" class=\"pnl-content imageDeck\">";
            DataRow dr2 = dt.Rows[0];
            data += "<a href=\"\" class=\"mainArt\"><img src=\"" + dr2["LinkImage"] + "\"  width=\"170\" height=\"110\"></a>";
            data += "</div>";
            data += "</div>";

            data += "<script type=\"text/javascript\">";
            data += "function initEventSlide() { AP.Core.JS.EventSlide.animation = true;AP.Core.JS.EventSlide.init('eventSlide');}AP.Core.JS.Initialization.call(initEventSlide);";
            data += "</script>";
        }
        catch
        {
            return data;
        }
        return data;
    }


    //public string BindVotes() //Muc vote
    //{
    //    string data = string.Empty;
    //    try
    //    {
    //        string time = DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss.000");
    //        DataTable dt = objvotes.SelecttblVotesDynamic_top("Top 1", "[status]=1 and StartDate<='" + time + "' and EndDate>='" + time + "'", "VoteId");
    //        DataTable dt2 = objVoteCri.SelecttblVoteCriteriaDynamic("[status]=1 and Voteid=" + dt.Rows[0]["Voteid"].ToString(), "VCID");

    //        data += "<p class=\"pnl-desc\">";
    //        data += dt.Rows[0]["VoteName"].ToString();
    //        data += "</p>";
    //        for (int i = 0; i < dt2.Rows.Count; i++)
    //        {
    //            DataRow dr = dt2.Rows[i];
    //            data += "<p>";
    //            data += "<input name=\"pollValue\" value=\"0\" type=\"radio\">";
    //            data += dt2.Rows[i]["VCName"].ToString();           
    //            data += "</p>";

    //        }
           
    //    }
    //    catch
    //    {
    //        return data;
    //    }
    //    return data;
    //}

   
}